package com.thrd.taiexhibition.fragement.enterprise;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.thrd.basicframework.bean.BaseFragment;
import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.bean.BeanCompany;
import com.thrd.taiexhibition.fresco.FrescoImage;
import com.thrd.taiexhibition.fresco.FrescoUtils;

/**
 * Top
 * @author: ${唐杰}
 * @date: 2021/3/30
 */
public class TopFragment extends BaseFragment {


    private FrameLayout mLayout;
    private LayoutInflater mLayoutInflater;
    private RadioGroup mRadioGroup;
    private FrescoImage mBuilding;

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_top;
    }

    @Override
    protected void setUpView(View mContentView) {
        mLayoutInflater = LayoutInflater.from(getMContext());
        mLayout = mContentView.findViewById(R.id.fl_top_layout);
        mRadioGroup = mContentView.findViewById(R.id.rg_layout);
        mBuilding = mContentView.findViewById(R.id.fi_building);
    }
    private BeanCompany mBeanCompany;
    @Override
    protected void setUpData() {
        //.inflate(R.layout.item,null);
        Bundle mBundle =getArguments();
        if(mBundle!=null){
            mBeanCompany= (BeanCompany) mBundle.getSerializable("BeanCompany");
        }
        FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mBuilding,mBeanCompany.getCompanyMansionImg());
        getHomeView(mLayout,mBeanCompany);

        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rb_home:
                        getHomeView(mLayout,mBeanCompany);
                        break;
                    case R.id.rb_brand:
                        getBrandView(mLayout,mBeanCompany);
                        break;
                    case R.id.rb_carte:
                        getCarteView(mLayout,mBeanCompany);
                        break;
                    case R.id.rb_panoramic:
                        getPanoramicView(mLayout,mBeanCompany);
                        break;
                }
            }
        });
    }
    private View mTopHome;
    /**
     * 首页界面
     * @param mLayout
     * @param mBeanCompany
     */
    private void getHomeView(FrameLayout mLayout,BeanCompany mBeanCompany){
        if(mTopHome==null){
            mTopHome = mLayoutInflater.inflate(R.layout.include_enterprise_top_home,null);
            TextView mEnterpriseName =mTopHome.findViewById(R.id.tv_enterprise_name);
            FrescoImage mLogo =mTopHome.findViewById(R.id.fi_logo);
            TextView mEnterpriseEnName =mTopHome.findViewById(R.id.tv_enterprise_en_name);
            TextView mMapAddress =mTopHome.findViewById(R.id.tv_map_address);
            FrescoImage mCodeResearchImg =mTopHome.findViewById(R.id.fi_code_research);
            FrescoImage mCodeAppletsImg=mTopHome.findViewById(R.id.fi_code_applets);
            mEnterpriseName.setText(TextUtils.isEmpty(mBeanCompany.getCompanyName())?"":mBeanCompany.getCompanyName());
            FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mLogo,mBeanCompany.getCompanyLogo());
            mMapAddress.setText(TextUtils.isEmpty(mBeanCompany.getCompanyAddress())?"":mBeanCompany.getCompanyAddress());
            FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mCodeAppletsImg,mBeanCompany.getCompanyQrCode());
            mEnterpriseEnName.setText(TextUtils.isEmpty(mBeanCompany.getCompanyAsName())?"":mBeanCompany.getCompanyAsName());
        }
        mLayout.removeAllViews();
        mLayout.addView(mTopHome,getResources().getDimensionPixelSize(R.dimen.qb_px_340),getResources().getDimensionPixelSize(R.dimen.qb_px_110));
    }

    private View mTopBrand;

    /**
     * 品牌展示
     * @param mLayout
     * @param mBeanCompany
     */
    private void getBrandView(FrameLayout mLayout,BeanCompany mBeanCompany){
        if(mTopBrand==null){
            mTopBrand = mLayoutInflater.inflate(R.layout.include_enterprise_top_brand,null);
            TextView mName=mTopBrand.findViewById(R.id.tv_name);
            TextView mContent=mTopBrand.findViewById(R.id.tv_content);
            mName.setText(TextUtils.isEmpty(mBeanCompany.getCompanyName())?"":mBeanCompany.getCompanyName());
            mContent.setText(TextUtils.isEmpty(mBeanCompany.getCompanyIntro())?"":mBeanCompany.getCompanyIntro());
        }
        mLayout.removeAllViews();
        mLayout.addView(mTopBrand,getResources().getDimensionPixelSize(R.dimen.qb_px_346),getResources().getDimensionPixelSize(R.dimen.qb_px_120));
    }

    private View mTopCarte;

    /**
     * 名片
     * @param mLayout
     * @param mBeanCompany
     */
    private void getCarteView(FrameLayout mLayout,BeanCompany mBeanCompany){
        if(mTopCarte==null){
            mTopCarte=mLayoutInflater.inflate(R.layout.include_enterprise_top_carte,null);
            FrescoImage mLogoImage= mTopCarte.findViewById(R.id.fi_logo_image);
            TextView mEnterpriseName= mTopCarte.findViewById(R.id.tv_enterprise_name);
            TextView mAddress= mTopCarte.findViewById(R.id.tv_address);
            FrescoImage mImage=  mTopCarte.findViewById(R.id.fl_image);
            TextView mContent= mTopCarte.findViewById(R.id.tv_content);
            FrescoImage mCodeImage=  mTopCarte.findViewById(R.id.fl_code_image);
            FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mLogoImage,mBeanCompany.getCompanyLogo());
            mEnterpriseName.setText(TextUtils.isEmpty(mBeanCompany.getCompanyName())?"":mBeanCompany.getCompanyName());
            mAddress.setText(TextUtils.isEmpty(mBeanCompany.getCompanyAddress())?"":mBeanCompany.getCompanyAddress());
            FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mImage,mBeanCompany.getCompanyBackImg());
            mContent.setText(TextUtils.isEmpty(mBeanCompany.getCompanyIntro())?"":mBeanCompany.getCompanyIntro());
            FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mCodeImage,mBeanCompany.getCompanyQrCode());
        }
        mLayout.removeAllViews();
        mLayout.addView(mTopCarte,getResources().getDimensionPixelSize(R.dimen.qb_px_346),getResources().getDimensionPixelSize(R.dimen.qb_px_110));
    }

    private View mTopPanoramic;
    /**
     * 名片
     * @param mLayout
     * @param mBeanCompany
     */
    private void getPanoramicView(FrameLayout mLayout,BeanCompany mBeanCompany){
        if(mTopPanoramic==null){
            mTopPanoramic=mLayoutInflater.inflate(R.layout.include_enterprise_top_panoramic,null);
            FrescoImage mFrescoImage=mTopPanoramic.findViewById(R.id.fi_image);
            FrescoUtils.getInstance().setPrefixProgressLoad(getMContext(),mFrescoImage,mBeanCompany.getCompanyPanoramaImg());
        }
        mLayout.removeAllViews();
        mLayout.addView(mTopPanoramic,getResources().getDimensionPixelSize(R.dimen.qb_px_285),getResources().getDimensionPixelSize(R.dimen.qb_px_105));
    }

}
